$(document).ready(function () {
    var $p = $('.mix_6x2arts_01');
    var cont = 0;
    $p.each(function() {
        var $parent = $(this);
        var $show = $parent.find('.mix_6x2arts_01_show');
        var $hide = $parent.find('.mix_6x2arts_01_hide');
        var $paginator = $parent.find('.nav_paginator_01');
        var $list = $parent.find('.mix_6x2arts_01_carousel ul li');
        if(cont == 0){
            $parent.find('.mix_6x2arts_01_carousel').slideDown();
            $paginator.slideDown();
        }

        else{
            $parent.find('.mix_6x2arts_01_carousel').slideUp();
            $paginator.slideUp();
            $show.addClass('selected');
            $hide.removeClass('selected');
        }


        $hide.click(function(e){
            e.preventDefault();
            var obj =  $parent.find('.mix_6x2arts_01_carousel');
            if(!$(this).hasClass('selected')){
                obj.slideDown();
                $paginator.slideDown();
                $show.removeClass('selected');
                $(this).addClass('selected');
            }
            
        });
        
        $show.click(function(e){
            e.preventDefault();
            var obj = $parent.find('.mix_6x2arts_01_carousel');
            if( !$(this).hasClass('selected')){
                obj.slideUp();
                $paginator.slideUp();
                $hide.removeClass('selected');
                $(this).addClass('selected');
            }
        });
        if ($(window).width() > 960){
            element_Margins(6);
        }
        if ( $(window).width() > 624 && $(window).width() <= 960){
            element_Margins(4);
        }
        $(window).resize(function() {
            if ($(window).width() > 960) {
                element_Margins(6);
            }
            if ($(window).width() > 624 && $(window).width() <= 960  ) {
                element_Margins(4);
            }
        });

        cont++;
    });
});




function element_Margins(total){

        var $parent = $('.mix_6x2arts_01');
    	var $show = $parent.find('.mix_6x2arts_01_show');
        var $hide = $parent.find('.mix_6x2arts_01_hide');
        var $paginator = $parent.find('.nav_paginator_01');
        var $list = $parent.find('.mix_6x2arts_01_carousel ul li');

    	var element = 1;
            if(total == 4){
                $list.each(function() {
                    if(element%4 == 0){
                        $(this).css({
                            'margin-right':'0px'
                        });
                    }
                    else{
                        $(this).css({
                            'margin-right':'25px'
                        }); 
                    }
                    element++;
                });
            }
            if(total == 6){
                $list.each(function() {
                    if(element%6 == 0){
                        $(this).css({
                            'margin-right':'0px'
                        });
                    }
                    else{
                        $(this).css({
                            'margin-right':'28px'
                        }); 
                    }
                    element++;
                });
            }
        }
